package com.tangfuzhong.test;

import com.tangfuzhong.aop.LogAspects;
import com.tangfuzhong.aop.LogAspects2;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.tangfuzhong.aop.MathCalculator;
import com.tangfuzhong.config.Config08_AOP_EnableAspectJAutoProxy;

public class IOCTest_08_AOP_EnableAspectJAutoProxy {
	
	@Test
	public void test01(){
		AnnotationConfigApplicationContext applicationContext
				= new AnnotationConfigApplicationContext(Config08_AOP_EnableAspectJAutoProxy.class);
		
		//1、不要自己创建对象,自己创建的对象无法被AOP拦截
//		MathCalculator mathCalculator = new MathCalculator();
//		mathCalculator.div(1, 1);
		MathCalculator mathCalculator = applicationContext.getBean(MathCalculator.class);
		LogAspects logAspects = (LogAspects)applicationContext.getBean("logAspects");
		LogAspects2 logAspects2 = (LogAspects2)applicationContext.getBean("logAspects2");
		mathCalculator.div(1, 10);
		
		applicationContext.close();
	}

}
